package top.kaoshanji.p2ch08a;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import top.kaoshanji.u1constant.FileConstant;

import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.nio.file.Path;
import java.nio.file.Paths;

/**
 * 代码清单-p2ch08a-02-250页b：使用javac工具API编译Java源代码
 * author kaoshanji
 * ^_^
 * create time 2025/1/21 19:00
 */
public class JavacExample02 {

    private static final Logger logger = LogManager.getLogger(JavacExample02.class);

    public static void main(String[] args) throws FileNotFoundException {
        logger.info("...代码清单-p2ch08a-02-250页b：使用javac工具API编译Java源代码...");

        // 输入的Java源代码的路径
        Path src = Paths.get(FileConstant.LOCAL_ROOT_PATH.concat("Hellop2ch08a02.java"));

        // 编译之后产生的class文件的输出路径
        Path output = Paths.get(FileConstant.LOCAL_ROOT_PATH);

        String[] strings = new String[] {src.toString(), "-d", output.toString()};
        PrintWriter out = new PrintWriter(Paths.get(FileConstant.LOCAL_ROOT_PATH.concat("p2ch08a02-output.txt")).toFile());

        // 关键代码...
        com.sun.tools.javac.Main.compile(strings, out);

    }

}
